package jpa_objects;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;

/**
 * @author Alejandro Casas
 * @version 1.0
 * @created 10-Dec-2012 1:01:03 AM
 */
@Entity
@NamedQueries({
@NamedQuery(name="searchBusiness", query="Select p from Business p inner join fetch " +
		"p.sports_of_interest as s  inner join fetch p.city as c inner join fetch p.type as ty where s.name = :sport" +
		"  and c.name = :city and c.country = :country and ty.type = :type"),
@NamedQuery(name="searchBusinessWraper", query="Select p from Business p inner join fetch " +
				"p.sports_of_interest as s  inner join fetch p.city as c inner join fetch p.type as ty where s.wraper = :wraper" +
				"  and c.name = :city and c.country = :country and ty.type = :type")
})
@PrimaryKeyJoinColumn(name="realMail")
public class Business extends User {

	//private long id;
	
	
	//private String address;
	//private double lat;
	//private double lng;
	//private String opening_hours;
	private Business_type type;
	private List<User> followers;
	private List<Branch> branchList;
	private List<Discount> discounts;
	//Reviews private List<Review> reviews;
	
	
	/**
	 * @return the discounts
	 */
	@OneToMany(targetEntity=Discount.class,cascade=CascadeType.ALL)
	public List<Discount> getDiscounts() {
		return discounts;
	}

	/**
	 * @param discounts the discounts to set
	 */
	public void setDiscounts(List<Discount> discounts) {
		this.discounts = discounts;
	}

	/**
	 * @return the branshList
	 */
	@OneToMany(targetEntity=Branch.class,cascade=CascadeType.ALL)
	public List<Branch> getBranshList() {
		return branchList;
	}

	/**
	 * @param branshList the branshList to set
	 */
	public void setBranshList(List<Branch> branshList) {
		this.branchList = branshList;
	}

	/**
	 * @return the id
	 *
	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 *
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the address
	 *
	public String getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 *
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return the discount
	 *
	public boolean isDiscount() {
		return discounts.size()>0?true:false;
	}

	
	/**
	 * @return the discount_description
	 *
	public String getDiscount_description() {
		return discount_description;
	}

	/**
	 * @param discount_description the discount_description to set
	 *
	public void setDiscount_description(String discount_description) {
		this.discount_description = discount_description;
	}

	/**
	 * @return the lat
	 *
	public double getLat() {
		return lat;
	}

	/**
	 * @param lat the lat to set
	 *
	public void setLat(double lat) {
		this.lat = lat;
	}

	/**
	 * @return the lng
	 *
	public double getLng() {
		return lng;
	}

	/**
	 * @param lng the lng to set
	 *
	public void setLng(double lng) {
		this.lng = lng;
	}

	/**
	 * @return the opening_hours
	 *
	public String getOpening_hours() {
		return opening_hours;
	}

	/**
	 * @param opening_hours the opening_hours to set
	 *
	public void setOpening_hours(String opening_hours) {
		this.opening_hours = opening_hours;
	}

	/**
	 * @return the type
	 */
	@OneToOne(targetEntity=Business_type.class,cascade=CascadeType.ALL)
	public Business_type getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Business_type type) {
		this.type = type;
	}

	/**
	 * @return the followers
	 */
	@OneToMany(targetEntity=User.class,cascade=CascadeType.ALL)
	public List<User> getFollowers() {
		return followers;
	}

	/**
	 * @param followers the followers to set
	 */
	public void setFollowers(List<User> followers) {
		this.followers = followers;
	}

	/**
	 * @return the reviews
	 *Reviews 
	@OneToMany(targetEntity=Review.class,cascade=CascadeType.ALL)
	public List<Review> getReviews() {
		return reviews;
	}

	/**
	 * @param reviews the reviews to set
	 *Reviews 
	public void setReviews(List<Review> reviews) {
		this.reviews = reviews;
	}
	

	/**
	 * @return the sports
	 *
	@OneToMany(targetEntity=Sport.class,cascade=CascadeType.ALL)
	public List<Sport> getSports() {
		return ;
	}

	/**
	 * @param sports the sports to set
	 *
	public void setSports(List<Sport> sports) {
		this.sports = sports;
	}
	*/
	public Business(){

	}

	/**
	 * @param carrier
	 * @param country
	 * @param description
	 * @param joinDate
	 * @param mail
	 * @param miniPicture
	 * @param name
	 * @param num_ratings
	 * @param password
	 * @param phone
	 * @param picture
	 * @param rating
	 * @param status
	 * @param address
	 * @param discount
	 * @param discount_description
	 * @param lat
	 * @param lng
	 * @param opening_hours
	 * @param type
	 * @param city
	 */
	public Business(String carrier, String country, String description,
			String joinDate, String mail, String miniPicture, String name,
			int num_ratings, String password, String phone, String picture,
			int rating, String status, Business_type type, City city,List<Branch> branchList
			,List<Sport> sports_of_interest) {
		super(carrier, country, description, joinDate, mail, miniPicture, name,
				num_ratings, password, phone, picture, rating, status,city);
		super.setSports_of_interest(sports_of_interest);
		//this.address = address;
		this.branchList=branchList;
		this.discounts=new ArrayList<Discount>();
		//this.discount_description = discount_description;
		//this.lat = lat;
		//this.lng = lng;
		//this.opening_hours = opening_hours;
		this.type = type;
		//Reviews this.reviews=new ArrayList<Review>();
		followers=new ArrayList<User>();
		//sports=new ArrayList<Sport>();
	}

	public void finalize() throws Throwable {
		super.finalize();
	}

}